const { contextBridge, ipcRenderer } = require('electron');

// 暴露安全的API给渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
  // 配置管理
  getConfig: () => ipcRenderer.invoke('get-config'),
  updateConfig: (config) => ipcRenderer.invoke('update-config', config),
  
  // 文件夹选择
  selectFolder: () => ipcRenderer.invoke('select-folder'),
  
  // AI模型测试
  testAIConnection: (modelConfig) => ipcRenderer.invoke('test-ai-connection', modelConfig),
  
  // AI聊天交互
  chatWithAI: (role, message) => ipcRenderer.invoke('chat-with-ai', role, message),
  
  // 文件上传
  uploadFile: () => ipcRenderer.invoke('upload-file'),
  
  // 文件操作
  readFile: (filePath) => ipcRenderer.invoke('read-file', filePath),
  writeFile: (filePath, content) => ipcRenderer.invoke('write-file', filePath, content),
  getSandboxFiles: () => ipcRenderer.invoke('get-sandbox-files'),
  
  // 沙盒文件操作
  sandboxReadFile: (filePath) => ipcRenderer.invoke('sandbox-read-file', filePath),
  sandboxWriteFile: (filePath, content) => ipcRenderer.invoke('sandbox-write-file', filePath, content),
  
  // 任务管理
  getTaskStatus: () => ipcRenderer.invoke('get-task-status'),
  getGanttData: () => ipcRenderer.invoke('get-gantt-data'),
  startTask: (taskId) => ipcRenderer.invoke('start-task', taskId),
  executeTasksParallel: (taskIds, maxConcurrent) => ipcRenderer.invoke('execute-tasks-parallel', taskIds, maxConcurrent),
  getExecutableTasks: () => ipcRenderer.invoke('get-executable-tasks'),
  resetTasks: () => ipcRenderer.invoke('reset-tasks'),
  getRoles: () => ipcRenderer.invoke('get-roles'),
  
  // 事件监听
  on: (channel, callback) => {
    ipcRenderer.on(channel, (event, ...args) => callback(...args));
  },
  
  // 移除事件监听
  removeAllListeners: (channel) => {
    ipcRenderer.removeAllListeners(channel);
  }
}); 